// components/review_project/index.js
import Dialog from '../../miniprogram_npm/@vant/weapp/dialog/dialog'
import Toast from '../../miniprogram_npm/@vant/weapp/toast/toast'
import api from '../../utils/api'

Component({
  options: {
    styleIsolation: 'shared',
  },
  /**
   * 组件的属性列表
   */
  properties: {
    competitionList: {
      type: Array,
      value: []
    }
  },

  /**
   * 组件的初始数据
   */
  data: {

  },

  /**
   * 组件的方法列表
   */
  methods: {
    modifyHandle(e) {
      const { id } = e.currentTarget.dataset
      wx.navigateTo({
        // url: `/pages/my_review_project_score/index?id=${id}`,
      })
    },
    cancelHandel(e) {
      const { id, idx } = e.currentTarget.dataset
      console.log(id)
      Dialog.confirm({
        title: '提示信息',
        message: '是否取消报名?'
      }).then(() => {
        // on confirm
        this.cancelmatch(id,idx)
      }).catch(() => {
        // on cancel
      });
    },

    async cancelmatch(id,idx) {
       const { code, data, msg }  = await api.send({ flag: '/signup/cancelSignUpMatch', id:id },{method:'post'})
       if(code === 1) {
         Toast('取消报名成功')
         this.data.competitionList.splice(idx,1)
         this.setData({competitionList:this.data.competitionList})
       }else {
         Toast(msg)
       }
     }
  }
})
